﻿package
{
	import castle_components.Tower;
	
	import flash.display.MovieClip;
	
	public class Castle extends MovieClip
	{
		public static var BASE_HEIGHT = 309, BASE_WIDTH = 413;
		public var game_handler:GameHandler;
		public var contained_areas:Array = new Array();
		
		public var red_primary_trainer_1, blue_primary_trainer_1, yellow_primary_trainer_1;
		public var red_primary_trainer_2, blue_primary_trainer_2, yellow_primary_trainer_2;
		public var red_primary_trainer_3, blue_primary_trainer_3, yellow_primary_trainer_3;
		public var castle_core;
		public var tower_0:Tower,tower_1:Tower,tower_2:Tower,tower_3:Tower,tower_4:Tower,tower_5:Tower;
		
		public function Castle(gH:GameHandler)
		{
			super();
			game_handler = gH;
			buildCastle();
		}
		
		public function buildCastle(){

			yellow_primary_trainer_1.game_handler = game_handler;
			yellow_primary_trainer_1.castle = this;
			red_primary_trainer_1.game_handler = game_handler;
			red_primary_trainer_1.castle = this;
			blue_primary_trainer_1.game_handler = game_handler;
			blue_primary_trainer_1.castle = this;
			
			yellow_primary_trainer_2.game_handler = game_handler;
			yellow_primary_trainer_2.castle = this;
			red_primary_trainer_2.game_handler = game_handler;
			red_primary_trainer_2.castle = this;
			blue_primary_trainer_2.game_handler = game_handler;
			blue_primary_trainer_2.castle = this;
			
			yellow_primary_trainer_3.game_handler = game_handler;
			yellow_primary_trainer_3.castle = this;
			red_primary_trainer_3.game_handler = game_handler;
			red_primary_trainer_3.castle = this;
			blue_primary_trainer_3.game_handler = game_handler;
			blue_primary_trainer_3.castle = this;
			castle_core.game_handler = game_handler;
			castle_core.castle = this;
			
			tower_0.game_handler = game_handler;
			tower_1.game_handler = game_handler;
			tower_2.game_handler = game_handler;
			tower_3.game_handler = game_handler;
			tower_4.game_handler = game_handler;
			tower_5.game_handler = game_handler;
			
			contained_areas.push(tower_0);
			contained_areas.push(tower_1);contained_areas.push(tower_2);contained_areas.push(tower_3);
			contained_areas.push(tower_4);contained_areas.push(tower_5);
			
			contained_areas.push(yellow_primary_trainer_1);
			contained_areas.push(red_primary_trainer_1);
			contained_areas.push(blue_primary_trainer_1);
			contained_areas.push(yellow_primary_trainer_2);
			contained_areas.push(red_primary_trainer_2);
			contained_areas.push(blue_primary_trainer_2);
			contained_areas.push(yellow_primary_trainer_3);
			contained_areas.push(red_primary_trainer_3);
			contained_areas.push(blue_primary_trainer_3);
			contained_areas.push(castle_core);
		}
		
		public function base_object_at(xx,yy){
			//convert to castle
			for(var i:int = 0; i < contained_areas.length; i++){
				if(contained_areas[i].hitTestPoint(xx,yy,true))
					return contained_areas[i];
			}
		}
	}
}